/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package be.wiim.rpi;

import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalInput;
import com.pi4j.io.gpio.PinPullResistance;
import com.pi4j.io.gpio.RaspiPin;
import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent;
import com.pi4j.io.gpio.event.GpioPinListenerDigital;

/**
 *
 * @author wimvandecasteele
 */
public class PassiveInfraredSensor {
   
   private final GpioController fGpioController = GpioFactory.getInstance();  
   private GpioPinDigitalInput fPin1 = null;
   
   public PassiveInfraredSensor() 
   {  
    fPin1 = fGpioController.provisionDigitalInputPin(RaspiPin.GPIO_01, "PIR Demo");  
    fPin1.addListener(new GpioPinListenerDigital() {
        @Override
        public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent pEvent) {
                if(pEvent.getState().isHigh())
                {
                    System.out.println(" Movement detected for pin:  "+pEvent.getPin());
                }
        }
        });
        for(;;){}
   }  
}
